﻿// *********************************************************************
// [DCOM Productions]
// [Copyright (C) DCOM Productions All rights reserved.]
// *********************************************************************

namespace BitFlex.Xdf {
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Represents an Xdf key / value pair
    /// </summary>
    public class XdfKey {
        /// <summary>
        /// Initializes a new instance of the BitFlex.Xdf.XdfKey class
        /// </summary>
        /// <param name="name">The name of the class</param>
        /// <param name="value">The key's value</param>
        public XdfKey(string name, object value) {
            this.Name = name;
            this.Value = value;
        }

        /// <summary>
        /// Initializes a new instance of the BitFlex.Xdf.XdfKey class
        /// </summary>
        /// <param name="name">The name of the class</param>
        public XdfKey(string name)
            : this(name, null) {
        }

        /// <summary>
        /// Gets or sets the name of the key
        /// </summary>
        public string Name {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the parent section that owns this key
        /// </summary>
        public XdfSection Parent {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the key's value
        /// </summary>
        public object Value {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the XPath of this Xdf section
        /// </summary>
        public string XPath {
            get {
                if (Parent == null) {
                    return this.Name;
                }
                else {
                    string xpath = string.Format("{0}//{1}",
                        Parent.XPath, this.Name);
                    return xpath;
                }
            }
        }

        public override string ToString() {
            return string.Format("{0} = {1}", this.Name, this.Value);
        }
    }
}
